package com.vivo.ActivitiUtils;

import com.thinkgem.jeesite.modules.sys.entity.Office;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.thinkgem.jeesite.modules.sys.service.OfficeService;
import com.thinkgem.jeesite.modules.sys.service.SystemService;
import com.vivo.common.quartz.SpringContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.List;


public class UserHelper implements Serializable{

//    @Autowired
//    private OfficeService officeService;
//
//    @Autowired
//    private SystemService systemService;

    public String getSuper(String name) {
        System.out.println("使用自定义方法了，哈哈！");
        String userName = "unfinded";

        OfficeService officeService = (OfficeService) SpringContextUtil.getBean("officeService");
        SystemService systemService = (SystemService) SpringContextUtil.getBean("systemService");

        User user = systemService.getUserByLoginName(name);

        if (user == null) {
            System.out.println("user is null fk, name is:" + name);
            return userName;
        }

        Office post = officeService.get(user.getPosition().getId());
        if (post != null) {
            Office superPost = officeService.get(post.getParentId());
            if (!superPost.getType().equals("3")) {
                System.out.println("上级组织机构不是职位，该员工无法进行此次操作：" + name);
            }
            List<User> userList = systemService.findUserByPositionId(superPost.getId());
            if (userList.size() == 0) {
                System.out.println("上级职位没有对应的人员存在，无法进行操作：" + name);
            }

            if (userList.size() > 1) {
                System.out.println("该用户有不止一个上级:" + name);
            }

            userName = userList.get(0).getLoginName();
        }

        return userName;
    }


    public void save() {
        System.out.println("print content by print()");
    }
}
